package com.phone580.app.sysapp;

import java.io.File;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.phone580.app.BaseActivity;
import com.phone580.app.R;
import com.phone580.app.untilty.AlertUtil;
import com.phone580.app.untilty.CommonUtility;

public class SysUninstallActivity extends BaseActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sys_uninstall_layout);
		Intent intent = getIntent();
		String title = intent.getStringExtra("title");
		final String path = intent.getStringExtra("path");
		Bitmap icon = (Bitmap)intent.getParcelableExtra("icon");
		ImageView ivIcon = (ImageView) findViewById(R.id.sys_uninstall_header_icon_iv);
		ivIcon.setImageBitmap(icon);
		TextView tvTitle = (TextView) findViewById(R.id.sys_uninstall_header_title_tv);
		tvTitle.setText(title);
		TextView tvInfo = (TextView) findViewById(R.id.sys_uninstall_info);
		tvInfo.setText(path + "\r\n卸载此系统应用");
		Button btnCancel = (Button) findViewById(R.id.button1);
		btnCancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		Button btnDelete = (Button) findViewById(R.id.button2);
		btnDelete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				AlertUtil.showAlert(SysUninstallActivity.this, R.string.warnning, "是否确认删除？", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						File file = new File(path);
						if (file.exists()) {
							
							String status = CommonUtility.getSystemMountStatus();
							String dev = status.split(" ")[0];
							String cmd = "mount -o remount " + dev + " /system";
							CommonUtility.execRootCmdSilent(cmd);
							String remove = "rm " + path;
							CommonUtility.execRootCmdSilent(remove);
							System.out.println("delete=");
						}
						finish();
					}
				}, new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						finish();
					}
				});
			}
		});
		
	}
}
